<template>
  <div>
    <!-- 搜索 -->
    <!-- 在库车质量信息维护 -->
    <TopFilter ref="TopFilterss" :list="topFilterInit" :cols="3" :collapse="collapse" labelWidth="90" @filterChange="changeHandle"></TopFilter>
    <!-- table -->
    <FilterTable ref="table" :columns="columns" :params="fetchParams" :dataSource="dataList" :datakey="'items'" :onColumnsChange="columns => (this.columns = columns)" :onRowSelectChange="selectChange">
      <template slot="controls" slot-scope="props">
        <multiuse-button size="small" type="primary" icon="el-icon-plus" @click="add()">下载</multiuse-button>
      </template>
    </FilterTable>
    <BaseDialog :visible.sync="visibleDetail" :title="'在库车质量信息维护明细'" destroyOnClose width="850px" :containerStyle="{height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px'}">
      <DetailForm @close="closeDetail" @save="saveDetail"></DetailForm>
    </BaseDialog>
    <BaseDialog :visible.sync="visibleEdit" :title="'在库车质量信息维护编辑'" destroyOnClose width="850px" :containerStyle="{height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px'}">
      <EditForm @close="closeEdit" @save="saveEdit"></EditForm>
    </BaseDialog>
    <BaseDialog :visible.sync="visible" :title="'车型选择'" destroyOnClose width="850px" :containerStyle="{height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px'}">
      <ModelVehicle @close="close" @save="save"></ModelVehicle>
    </BaseDialog>
  </div>
</template>
<script>
// import { dictionary } from '@/utils/dictMixin';
import DetailForm from './DetailForm.vue';
import EditForm from './EditForm.vue';
import ModelVehicle from '@/pages/claimDemage/tools/ModelVehicle.vue';
// import res from '@/mock/tableData';

export default {
  // mixins: [dictionary],
  components: {
    DetailForm,
    EditForm,
    ModelVehicle
  },
  data() {
    return {
      dataList: [],
      visible: false,
      visibleDrawer: false,
      collapse: false,
      infoId: null,
      topFilterInit: this.topFilterInitFun(),
      flterValue: {}, //参数
      columns: this.creatHeader(),
      // fetchApi: getUser,
      fetchParams: {}, //ipa 接口
      selectedRows: [], //选中经销商
      visibleDetail: false,
      visibleEdit: false
    };
  },
  created() {
    // this.dataList = [...res.data.items];
    console.log(this.dataList);
  },
  methods: {
    //搜索数据
    topFilterInitFun() {
      return [
        { type: 'INPUT', label: 'VIN', fieldName: 'modelCode', placeholder: '请输入', initialValue: '' },
        {
          type: 'INPUT',
          label: '车型',
          fieldName: 'modelCode',
          readonly: true, // 只读
          unitRender: p => {
            return (
              <div>
                <multiuse-button icon="el-icon-search" onClick={() => this.modelTurnOn()}/>
              </div>
            );
          }
        },
        {
          type: 'SELECT',
          label: '维护状态',
          fieldName: 'wmStatus',
          itemList: [{text: '热点', value: '1'}, {text: '资讯', value: '2'}],
          readonly: true // 只读
        },
        {
          type: 'SELECT',
          label: '电池状态',
          fieldName: 'wmStatus',
          itemList: [{text: '热点', value: '1'}, {text: '资讯', value: '2'}],
          readonly: true // 只读
        },
        {
          type: 'SELECT',
          label: '使用状态',
          fieldName: 'wmStatus',
          itemList: [{text: '热点', value: '1'}, {text: '资讯', value: '2'}],
        },
        { type: 'RANGE_DATE', label: '检测日期', fieldName: 'startTime|endTime', placeholder: '请输入', initialValue: '' }
      ];
    },
    //搜索获取数据
    changeHandle(val) {
      this.fetchParams = val;
      console.log(val);
    },
    //table表头和数据源
    creatHeader() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '操作',
          dataIndex: 'column-action',
          width: 100,
          fixed: 'left',
          render: props => {
            return (
              <div style="text-align:center">
                <multiuse-button type="primary" icon="el-icon-edit" onClick={() => this.edit()} circle></multiuse-button>
                <multiuse-button type="primary" icon="el-icon-document" onClick={() => this.detail()} circle></multiuse-button>
              </div>
            );
          }
        },
        { title: 'VIN', dataIndex: 'wmStatus', sorter: true },
        { title: '使用状态', dataIndex: 'whName', sorter: true },
        { title: '电池状态', dataIndex: 'whCode', sorter: true },
        { title: '最近一次处理状态', dataIndex: 'modelName', sorter: true },
        { title: '车型', dataIndex: 'modelCode', sorter: true },
        { title: '生产日期', dataIndex: 'createdBy', sorter: true },
        { title: '入库日期', dataIndex: 'createdAt', sorter: true },
        { title: '在库时长（月）', dataIndex: 'updatedBy', sorter: true },
        { title: '连续异常次数', dataIndex: 'updatedAt', sorter: true },
        { title: '最近处理人', dataIndex: 'updatedAt', sorter: true },
        { title: '处理时间', dataIndex: 'updatedAt', sorter: true }
      ];
    },
    //选中
    selectChange(rows) {
      this.selectedRows = rows;
      console.log(this.selectedRows);
    },
    modelTurnOn() {
      this.visible = true;
    },
    exportFileBtn() {
      this.$refs.TopFilterss.SUBMIT_FORM();
    },
    detail() {
      this.visibleDetail = true;
    },
    edit() {
      this.visibleEdit = true;
    },
    closeDetail() {
      this.visibleDetail = false;
      this.fetchParams = { ...this.fetchParams };
    },
    saveDetail() {
      this.visibleDetail = false;
      this.fetchParams = { ...this.fetchParams };
    },
    closeEdit() {
      this.visibleEdit = false;
      this.fetchParams = { ...this.fetchParams };
    },
    saveEdit() {
      this.visibleEdit = false;
      this.fetchParams = { ...this.fetchParams };
    },
    close() {
      this.visible = false;
      this.fetchParams = { ...this.fetchParams };
    },
    save(obj) {
      this.visible = false;
      this.topFilterInit.find(x => x.fieldName == 'modelCode').initialValue = obj[0].address;
      this.fetchParams = { ...this.fetchParams };
    },
  }
  // mounted() {
  //   this.BaseTable = this.$refs.listModal.$refs.pageTable;
  // }
};
</script>

<style lang="less" scoped></style>
